(in-package :xlui)
(use-package :lib.gl)

(defun sample-stage ()
  (let* ((app (slui (:theater
		     :title "A Stage to a Play." :width 640 :height 480 ;:track-mouse "true"
		     (:stage :name "SampleWorld"))))
	 (view (view-named app "SampleWorld"))
	 (floor (make-ground :name "Ground" :pos (cp:cpv 0.0 0.0) :stage view))
	 (block (make-standard-block :name "Block" :pos (cp:cpv 0.0 10.0) :stage view))
	 (ninja (make-ninja-pea :name "NinjaGaiden" :pos (cp:cpv 1.0 15.0) :stage view)))
    (setf (cp:gravity (space view)) (cp:cpv 0.0 0.0))
    (start-window-animation app "SampleWorld")
    app))

(defclass bb-test-view (agent-3d-view)
  ()
  (:documentation "Tests for Collision detection using bounding boxes."))

(defclass obb (agent-3d gl::bounding-box)
  ())

(defmethod x ((a obb))
  (gl:gl-aref (gl::center a) 0))
(defmethod y ((a obb))
  (gl:gl-aref (gl::center a) 1))
(defmethod z ((a obb))
  (gl:gl-aref (gl::center a) 2))

(defmethod draw ((a obb))
  (with-slots ((u gl::u) (e gl::e)) a
    (glcolor3f 1.0 1.0 1.0)
    (dotimes (i 3)
      (let ((u0 (svref u (mod (+ i 1) 3)))
	    (u1 (svref u (mod (+ i 2) 3)))
	    (e0 (svref e (mod (+ i 1) 3)))
	    (e1 (svref e (mod (+ i 2) 3))))
	(glvertex3dv (m+ (m* e0 u0) (m* e1 u1)))
	(glvertex3dv (m+ (m* -1 e0 u0) (m* e1 u1)))
	(glvertex3dv (m+ (m* -1 e0 u0) (m* -1 e1 u1)))
	(glvertex3dv (m+ (m* e0 u0) (m* -1 e1 u1)))))))

	    
(defun test-bb-0 ()
  (let* ((app (slui (:application-window :title "Bounding Boxes." :width 640 :height 480
					 (:bb-test-view :name "BoundingBoxes")))))
    app))

(defun test-method-list ()
  (ccl::compute-applicable-methods-using-classes #'lui::VIEW-LEFT-MOUSE-DRAGGED-EVENT-HANDLER
                                                 (list (find-class 'stage)
                                                       (find-class t)
                                                       (find-class t)
                                                       (find-class t)
                                                       (find-class t))))

;;;;
			      
(in-package #:log5)

(start-sender 'debug-log
	      (stream-sender :location *standard-output*)
	      :category-spec '(trace)
	      :output-spec '(time message))